import { Body, Controller, Get, Post, Query } from '@nestjs/common';
import { ApiResponse, ApiTags, ApiSecurity, ApiOperation } from '@nestjs/swagger';
import { ADMIN_PREFIX } from 'src/modules/admin/admin.constants';
import {
  CreateCategoryDto,
  UpdateCategoryDto,
  DelCategories,
  ListCategoryDto,
} from './category.dto';
import Category from 'src/entities/admin/sys-category.entity';
import { SysCategoryService } from './category.service';
@ApiSecurity(ADMIN_PREFIX)
@ApiTags('分类模块')
@Controller('category')
export class SysCategoryController {
  constructor(private readonly categoryService: SysCategoryService) {}

  /**
   * 添加标签
   * @param category
   */
  @ApiOperation({
    summary: '添加分类',
  })
  @ApiResponse({ status: 200, description: 'add', type: [CreateCategoryDto] })
  @Post('add')
  create(@Body() category: CreateCategoryDto) {
    return this.categoryService.create(category);
  }

  /**
   * 获取所有标签
   */
  @ApiOperation({
    summary: '获取所有分类',
  })
  @ApiResponse({ status: 200, description: 'list' })
  @Get('list')
  findAll(@Query() queryParams: ListCategoryDto): Promise<Category[]> {
    return this.categoryService.findAll(queryParams);
  }

  /**
   * 获取指定标签
   * @param id
   */
  @ApiOperation({
    summary: '获取指定分类',
  })
  @ApiResponse({ status: 200, description: 'info' })
  @Get('info')
  findById(@Query('id') id) {
    return this.categoryService.findById(id);
  }

  /**
   * 更新标签
   * @param id
   * @param category
   */
  @ApiOperation({
    summary: '更新分类',
  })
  @ApiResponse({ status: 200, description: 'update' })
  @Post('update')
  updateById(@Body() category: UpdateCategoryDto) {
    return this.categoryService.updateById(category);
  }

  /**
   * 删除标签
   * @param id
   */
  @ApiOperation({
    summary: '删除分类',
  })
  @ApiResponse({ status: 200, description: 'delete' })
  @Post('delete')
  deleteById(@Body() dto: DelCategories) {
    return this.categoryService.deleteById(dto.id);
  }
}
